package edu.ccut.saturn.basecomponent.baseservicecomponent;

import java.io.BufferedReader;
import java.io.FileReader;

import edu.ccut.saturn.component.DefaultComponent;
import edu.ccut.saturn.component.IParameterContext;

public class GetStringFromFile extends DefaultComponent {

	@Override
	public void execute(IParameterContext parameterContext) throws Exception {
		super.execute(parameterContext);
		String path = (String) parameterContext.getParameterValue(0);
		if (path != null) {
			FileReader fileReader = new FileReader(path);
			BufferedReader bufferedReader = new BufferedReader(fileReader);
			String line = null;
			StringBuffer stringBuffer = new StringBuffer();
			while ((line = bufferedReader.readLine()) != null) {
				stringBuffer.append(line);
			}
			bufferedReader.close();
			fileReader.close();
			
			parameterContext.setParameter(1, stringBuffer.toString());
		}
	}

}
